import React, { useState } from 'react';
import ReactDom from 'react-dom';
import { useEffect } from 'react/cjs/react.development';

const App = () => {
  const [count, setCount] = useState(0);
  const [msg, setMsg] = useState('');

  useEffect(() => {
    console.log('我被执行了  ----->  ');
    document.title = count + msg;
  }, [count, msg]); // [依赖项, 依赖项2,...] 多个依赖项，表示同时监听多个状态的变化

  return (
    <div>
      msg -- {msg}
      <hr />
      count -- {count}
      <hr />
      <button onClick={() => setMsg(msg + '~')}>点我修改msg</button>
      <button onClick={() => setCount(count + 1)}>点我修改count</button>
    </div>
  );
};
ReactDom.render(<App />, document.getElementById('root'));
